package com.data.service.system.impl;

import com.data.domain.manage.Orginfo;
import com.data.domain.manage.OrginfoCriteria;
import com.data.domain.report.Prtryinfo;
import com.data.domain.report.PrtryinfoCriteria;
import com.data.domain.report.Prtryinfo;
import com.data.domain.report.PrtryinfoCriteria;
import com.data.josonbean.select.SelectModel;
import com.data.mapper.report.PrtryinfoMapper;
import com.data.model.SystemModel;
import com.data.service.system.PrtryinfoService;
import com.data.utill.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service(value = "prtryinfoService")
public class PrtryinfoServiceImpl implements PrtryinfoService {

    @Autowired
    private PrtryinfoMapper prtryinfoMapper;

    @Override
    public List<Prtryinfo> getPrtryinfo(SystemModel systemModel){
        PrtryinfoCriteria prtryinfoCriteria=new PrtryinfoCriteria();
        PrtryinfoCriteria.Criteria criteria=prtryinfoCriteria.createCriteria();
        if(StringUtils.isNoNullString(systemModel.getCode())){
            criteria.andCodeEqualTo(systemModel.getCode());
        }
        if(StringUtils.isNoNullString(systemModel.getName())){
            criteria.andNameLike("%"+systemModel.getName()+"%");
        }
        prtryinfoCriteria.setOrderByClause("id asc");
        return prtryinfoMapper.selectByExample(prtryinfoCriteria);
    }

    /**
     * 业务种类信息插入
     * @param systemModel
     * @return
     */
    @Override
    public int insertPrtryinfo(SystemModel systemModel){
        PrtryinfoCriteria prtryinfoCriteria=new PrtryinfoCriteria();
        Prtryinfo data = new Prtryinfo();
        data.setCode(systemModel.getCode());
        data.setName(systemModel.getName());
        return prtryinfoMapper.insertSelective(data);
    }

    /**
     * 业务种类信息修改
     * @param systemModel
     * @return
     */
    @Override
    public int modifyPrtryinfo(SystemModel systemModel ,int id){
        PrtryinfoCriteria prtryinfoCriteria=new PrtryinfoCriteria();
        prtryinfoCriteria.createCriteria().andIdEqualTo(id);
        Prtryinfo data = new Prtryinfo();
        data.setCode(systemModel.getCode());
        data.setName(systemModel.getName());
        return prtryinfoMapper.updateByExampleSelective(data,prtryinfoCriteria);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Prtryinfo getPrtryinfoById(int id) {
        PrtryinfoCriteria prtryinfoCriteria=new PrtryinfoCriteria();
        prtryinfoCriteria.createCriteria().andIdEqualTo(id);
        List<Prtryinfo> data = prtryinfoMapper.selectByExample(prtryinfoCriteria);
        if (null!=data) {
            return data.get(0);
        }else{
            return null;
        }
    }

    /**
     * select2查询用
     * @param name
     * @return
     */
    @Override
    public List<SelectModel> selectPrtry(String name){
        PrtryinfoCriteria prtryinfoCriteria=new PrtryinfoCriteria();
        PrtryinfoCriteria.Criteria criteria=prtryinfoCriteria.createCriteria();
        if(StringUtils.isNoNullString(name)){
            criteria.andNameLike("%"+name+"%");
        }
        prtryinfoCriteria.setOrderByClause("code asc");
        prtryinfoCriteria.setDistinct(true);
        List<Prtryinfo> list=prtryinfoMapper.selectByExample(prtryinfoCriteria);
        List<SelectModel> data = new ArrayList<>();
        SelectModel model=null;
        model=new SelectModel();
        model.setId(""+"-"+"全部-");
        model.setText(""+"-"+"全部-");
        data.add(model);
        for(Prtryinfo prtryinfo:list){
            model=new SelectModel();
            model.setText(prtryinfo.getCode()+"-"+prtryinfo.getName());
            model.setId(prtryinfo.getCode()+"-"+prtryinfo.getName());
            data.add(model);
        }
        return data;
    }
}
